/*
 * Copyright (C) 2011 Macambira Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.googlecode.control;

import com.googlecode.entity.Disciplina;
import java.util.LinkedList;
import java.util.List;

/**
 * Classe responsavel por realizar o CRUD de disciplina
 * 
 * @version 0.1 20 Set 2011
 * @author Tony Silva | tony.silva@dce.ufpb.br
 */
public class ControlDisciplina {
    
    private List<Disciplina> listDisciplinas;
    
    public ControlDisciplina() {
        this.listDisciplinas = new LinkedList<Disciplina>();
    }
    
    public void addDisciplina(Disciplina disciplina) {
        this.listDisciplinas.add(disciplina);
    }
    
    public List<Disciplina> getDisciplina() {
        return this.listDisciplinas;
    }
    
    public Disciplina getDisciplinaId(String id) {
        for(Disciplina disc : listDisciplinas) {
            if(disc.getId().equalsIgnoreCase(id)) {
                return disc;
            }
        }
        return null;
    }
    
    public Disciplina getDisciplinaNome(String nome) {
        for(Disciplina disc : listDisciplinas){
            if(disc.getNome().equalsIgnoreCase(nome)) {
                return disc;
            }
        }
        return null;
    }
    
    public void removerDisciplinaNome(String nome) {
        for(Disciplina disc : listDisciplinas) {
            if(disc.getNome().equalsIgnoreCase(nome)) {
                this.listDisciplinas.remove(disc);
                break;
            }
        }
    }
    
    public void removerDisciplinaId(String id) {
        for(Disciplina disc : listDisciplinas) {
            if(disc.getId().equalsIgnoreCase(id)) {
                this.listDisciplinas.remove(disc);
                break;
            }
        }
    }
    
    public void updateDisciplina(Disciplina disciplina) {
        for(Disciplina disc : listDisciplinas) {
            if(disc.getId().equalsIgnoreCase(disciplina.getId())); {
                removerDisciplinaId(disciplina.getId());
                this.listDisciplinas.add(disciplina);
                break;
            }
        }
    }
    
    public int getSize() {
        return listDisciplinas.size();
    }
}
